
# 临时解决方案：跳过会话状态检查，直接发送消息
def send_kf_message_workaround(self, open_kfid, external_userid, msg_type, content, token=None):
    """
    发送客服消息（临时解决方案，跳过IP限制）
    """
    try:
        if not token:
            token = self.get_access_token()
        if not token:
            logger.error("无法获取access_token")
            return None
        
        url = "https://qyapi.weixin.qq.com/cgi-bin/kf/send_msg"
        params = {'access_token': token}
        
        # 生成唯一的msgid
        unique_msgid = f"wx_{int(time.time())}_{uuid.uuid4().hex[:8]}"
        
        data = {
            "open_kfid": open_kfid,
            "touser": external_userid,
            "msgtype": msg_type,
            "text": {"content": content},
            "msgid": unique_msgid
        }
        
        logger.info(f"📤 直接发送消息（跳过会话检查）...")
        logger.info(f"   external_userid: {external_userid}")
        logger.info(f"   content: {content}")
        
        response = self.session.post(url, params=params, json=data, timeout=10)
        result = response.json()
        
        if result.get('errcode') == 0:
            logger.info(f"✅ 消息发送成功")
            return result
        else:
            logger.error(f"❌ 消息发送失败: {result}")
            return None
            
    except Exception as e:
        logger.error(f"❌ 发送消息异常: {str(e)}")
        return None
